
/*
 * NewSaleFrame.java
 *
 * Created on Jun 15, 2011, 12:10:41 PM
 */
package ui.gui;

import java.awt.event.KeyEvent;
import ui.gui.table.renderer.DecimalCellRenderer;
import controller.NoOpenSaleException;
import controller.OrderController;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Arrays;
import javax.swing.JOptionPane;
import model.Customer;
import model.Delivery;
import model.NoSuchItemException;
import model.OrderLineItem;
import ui.gui.table.model.SaleTableModel;

/**
 * Represents a frame for executing sales
 * @author k4emic
 */
public class NewSaleFrame extends javax.swing.JFrame {

    private OrderController controller;
    private SaleTableModel tableModel;

    /** Creates new form NewSaleFrame */
    public NewSaleFrame() {
        initComponents();

        controller = new OrderController();

        setDefaultValues();

        initTable();

    }

    private void initTable() {
        tableModel = new SaleTableModel(controller.getSale());
        tblItems.setModel(tableModel);

        tblItems.setDefaultRenderer(java.lang.Double.class, new DecimalCellRenderer());
    }

    /**
     * Sets default values in all text fields (and some labels)
     */
    private void setDefaultValues() {
        updateTotal();
        updateCustomerInfo();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlSale = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tblItems = new javax.swing.JTable();
        lblItemNo = new javax.swing.JLabel();
        lblQty = new javax.swing.JLabel();
        lblDiscountInput = new javax.swing.JLabel();
        btnAdd = new javax.swing.JButton();
        txtDiscountPct = new javax.swing.JTextField();
        txtItemNo = new javax.swing.JTextField();
        txtQty = new javax.swing.JTextField();
        lblDiscountPct = new javax.swing.JLabel();
        btnRemoveLines = new javax.swing.JButton();
        pnlTotals = new javax.swing.JPanel();
        lblTotal = new javax.swing.JLabel();
        lblTotalDisplay = new javax.swing.JLabel();
        lblDiscountDisplay = new javax.swing.JLabel();
        lblDiscount = new javax.swing.JLabel();
        lblDeliveryDisplay = new javax.swing.JLabel();
        lblDelivery = new javax.swing.JLabel();
        lblSubTotal = new javax.swing.JLabel();
        lblSubTotalDispl = new javax.swing.JLabel();
        pnlDelivery = new javax.swing.JPanel();
        lblDeliveryName = new javax.swing.JLabel();
        lblDeliveryAddress = new javax.swing.JLabel();
        lblDeliveryZipCode = new javax.swing.JLabel();
        lblDeliveryCity = new javax.swing.JLabel();
        txtDeliveryName = new javax.swing.JTextField();
        txtDeliveryAddress = new javax.swing.JTextField();
        txtDeliveryZipCode = new javax.swing.JTextField();
        txtDeliveryCity = new javax.swing.JTextField();
        btnDeliveryUseCustomerInfo = new javax.swing.JButton();
        lblDeliveryPrice = new javax.swing.JLabel();
        txtDeliveryPrice = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        btnDeliverySave = new javax.swing.JButton();
        btnDeliveryClear = new javax.swing.JButton();
        pnlCustomer = new javax.swing.JPanel();
        lblPhone = new javax.swing.JLabel();
        btnReadCustomer = new javax.swing.JButton();
        txtPhone = new javax.swing.JTextField();
        lblCustomerName = new javax.swing.JLabel();
        lblCustomerAddress = new javax.swing.JLabel();
        lblCustomerZipCode = new javax.swing.JLabel();
        lblCustomerNameValue = new javax.swing.JLabel();
        lblCustomerAddressValue = new javax.swing.JLabel();
        lblCustomerZipCodeValue = new javax.swing.JLabel();
        lblCustomerCity = new javax.swing.JLabel();
        lblCustomerCityValue = new javax.swing.JLabel();
        btnCustomerClear = new javax.swing.JButton();
        pnlButtons = new javax.swing.JPanel();
        btnCancel = new javax.swing.JButton();
        btnConfirm = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Salg - Nyt salg");
        setMinimumSize(new java.awt.Dimension(740, 450));
        setResizable(false);

        tblItems.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tblItems.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tblItemsKeyReleased(evt);
            }
        });
        jScrollPane4.setViewportView(tblItems);

        lblItemNo.setText("Varenummer");

        lblQty.setText("Antal");

        lblDiscountInput.setText("Rabat:");

        btnAdd.setText("Tilføj");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        txtDiscountPct.setText("0");
        txtDiscountPct.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtDiscountPctFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtDiscountPctFocusLost(evt);
            }
        });

        txtItemNo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtItemNoActionPerformed(evt);
            }
        });

        txtQty.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtQty.setText("1");
        txtQty.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtQtyActionPerformed(evt);
            }
        });
        txtQty.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtQtyFocusGained(evt);
            }
        });

        lblDiscountPct.setText("%");

        btnRemoveLines.setText("Fjern markerede vare");
        btnRemoveLines.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveLinesActionPerformed(evt);
            }
        });

        lblTotal.setFont(new java.awt.Font("Ubuntu", 1, 15));
        lblTotal.setText("Total:");

        lblTotalDisplay.setFont(new java.awt.Font("Ubuntu", 1, 15));
        lblTotalDisplay.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblTotalDisplay.setText("totalDispl");

        lblDiscountDisplay.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblDiscountDisplay.setText("discountDispl");

        lblDiscount.setText("Rabat:");

        lblDeliveryDisplay.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblDeliveryDisplay.setText("deliveryDispl");

        lblDelivery.setText("Levering:");

        lblSubTotal.setText("Subtotal");

        lblSubTotalDispl.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblSubTotalDispl.setText("subTotaldispl");

        javax.swing.GroupLayout pnlTotalsLayout = new javax.swing.GroupLayout(pnlTotals);
        pnlTotals.setLayout(pnlTotalsLayout);
        pnlTotalsLayout.setHorizontalGroup(
            pnlTotalsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlTotalsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlTotalsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblSubTotal)
                    .addComponent(lblTotal)
                    .addComponent(lblDelivery)
                    .addComponent(lblDiscount))
                .addGap(18, 18, Short.MAX_VALUE)
                .addGroup(pnlTotalsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblSubTotalDispl, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblDiscountDisplay, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblDeliveryDisplay, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblTotalDisplay, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );

        pnlTotalsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {lblDeliveryDisplay, lblDiscountDisplay, lblSubTotalDispl, lblTotalDisplay});

        pnlTotalsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {lblDelivery, lblDiscount, lblSubTotal, lblTotal});

        pnlTotalsLayout.setVerticalGroup(
            pnlTotalsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlTotalsLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlTotalsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSubTotal)
                    .addComponent(lblSubTotalDispl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlTotalsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDiscountDisplay)
                    .addComponent(lblDiscount))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlTotalsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDelivery)
                    .addComponent(lblDeliveryDisplay))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlTotalsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTotal)
                    .addComponent(lblTotalDisplay))
                .addGap(6, 6, 6))
        );

        javax.swing.GroupLayout pnlSaleLayout = new javax.swing.GroupLayout(pnlSale);
        pnlSale.setLayout(pnlSaleLayout);
        pnlSaleLayout.setHorizontalGroup(
            pnlSaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlSaleLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlSaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlSaleLayout.createSequentialGroup()
                        .addGroup(pnlSaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblItemNo)
                            .addComponent(txtItemNo, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnRemoveLines))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlSaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlSaleLayout.createSequentialGroup()
                                .addComponent(txtQty, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnAdd))
                            .addComponent(lblQty)
                            .addGroup(pnlSaleLayout.createSequentialGroup()
                                .addComponent(lblDiscountInput)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtDiscountPct, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(lblDiscountPct)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(pnlTotals, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        pnlSaleLayout.setVerticalGroup(
            pnlSaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlSaleLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlSaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlSaleLayout.createSequentialGroup()
                        .addGroup(pnlSaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnRemoveLines)
                            .addComponent(txtDiscountPct, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblDiscountPct)
                            .addComponent(lblDiscountInput))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlSaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblItemNo)
                            .addComponent(lblQty))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlSaleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtItemNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtQty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnAdd)))
                    .addComponent(pnlTotals, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlDelivery.setBorder(javax.swing.BorderFactory.createTitledBorder("Levering"));

        lblDeliveryName.setText("Navn");

        lblDeliveryAddress.setText("Adresse");

        lblDeliveryZipCode.setText("Postnr");

        lblDeliveryCity.setText("By");

        txtDeliveryName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDeliveryNameActionPerformed(evt);
            }
        });
        txtDeliveryName.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtDeliveryNameFocusLost(evt);
            }
        });

        txtDeliveryZipCode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDeliveryZipCodeActionPerformed(evt);
            }
        });

        txtDeliveryCity.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDeliveryCityActionPerformed(evt);
            }
        });

        btnDeliveryUseCustomerInfo.setText("Brug kundeoplysninger");
        btnDeliveryUseCustomerInfo.setEnabled(false);
        btnDeliveryUseCustomerInfo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeliveryUseCustomerInfoActionPerformed(evt);
            }
        });

        lblDeliveryPrice.setText("Pris");

        txtDeliveryPrice.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDeliveryPriceActionPerformed(evt);
            }
        });

        btnDeliverySave.setText("Gem");
        btnDeliverySave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeliverySaveActionPerformed(evt);
            }
        });

        btnDeliveryClear.setText("Ryd");
        btnDeliveryClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeliveryClearActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlDeliveryLayout = new javax.swing.GroupLayout(pnlDelivery);
        pnlDelivery.setLayout(pnlDeliveryLayout);
        pnlDeliveryLayout.setHorizontalGroup(
            pnlDeliveryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDeliveryLayout.createSequentialGroup()
                .addGroup(pnlDeliveryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                    .addComponent(btnDeliveryUseCustomerInfo)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlDeliveryLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pnlDeliveryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(lblDeliveryName)
                            .addComponent(lblDeliveryAddress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblDeliveryZipCode)
                            .addComponent(lblDeliveryPrice))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pnlDeliveryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtDeliveryAddress, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE)
                            .addComponent(txtDeliveryName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlDeliveryLayout.createSequentialGroup()
                                .addComponent(txtDeliveryZipCode, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblDeliveryCity)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtDeliveryCity, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE))
                            .addGroup(pnlDeliveryLayout.createSequentialGroup()
                                .addComponent(txtDeliveryPrice, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnDeliverySave, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnDeliveryClear, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        pnlDeliveryLayout.setVerticalGroup(
            pnlDeliveryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDeliveryLayout.createSequentialGroup()
                .addComponent(btnDeliveryUseCustomerInfo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDeliveryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDeliveryName)
                    .addComponent(txtDeliveryName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDeliveryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDeliveryAddress)
                    .addComponent(txtDeliveryAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDeliveryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDeliveryZipCode)
                    .addComponent(txtDeliveryZipCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDeliveryCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDeliveryCity))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addGroup(pnlDeliveryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtDeliveryPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDeliveryPrice)
                    .addComponent(btnDeliveryClear)
                    .addComponent(btnDeliverySave))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlCustomer.setBorder(javax.swing.BorderFactory.createTitledBorder("Kundeinformation"));

        lblPhone.setLabelFor(txtPhone);
        lblPhone.setText("Telefonnr:");

        btnReadCustomer.setText("Indlæs");
        btnReadCustomer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReadCustomerActionPerformed(evt);
            }
        });

        txtPhone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPhoneActionPerformed(evt);
            }
        });

        lblCustomerName.setText("Navn:");

        lblCustomerAddress.setText("Adresse:");

        lblCustomerZipCode.setText("Postnr:");

        lblCustomerNameValue.setText("name");

        lblCustomerAddressValue.setText("address");

        lblCustomerZipCodeValue.setText("zip");

        lblCustomerCity.setText("By:");

        lblCustomerCityValue.setText("city");

        btnCustomerClear.setText("Ryd");
        btnCustomerClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCustomerClearActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlCustomerLayout = new javax.swing.GroupLayout(pnlCustomer);
        pnlCustomer.setLayout(pnlCustomerLayout);
        pnlCustomerLayout.setHorizontalGroup(
            pnlCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCustomerLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblCustomerZipCode)
                    .addComponent(lblCustomerAddress)
                    .addComponent(lblPhone)
                    .addComponent(lblCustomerName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlCustomerLayout.createSequentialGroup()
                        .addComponent(txtPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnReadCustomer, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6))
                    .addComponent(lblCustomerNameValue)
                    .addComponent(lblCustomerAddressValue)
                    .addGroup(pnlCustomerLayout.createSequentialGroup()
                        .addComponent(lblCustomerZipCodeValue)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblCustomerCity)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblCustomerCityValue)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCustomerClear, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pnlCustomerLayout.setVerticalGroup(
            pnlCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCustomerLayout.createSequentialGroup()
                .addGroup(pnlCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPhone)
                    .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCustomerClear)
                    .addComponent(btnReadCustomer))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCustomerNameValue)
                    .addComponent(lblCustomerName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCustomerAddress)
                    .addComponent(lblCustomerAddressValue))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCustomerZipCode)
                    .addComponent(lblCustomerZipCodeValue)
                    .addComponent(lblCustomerCity)
                    .addComponent(lblCustomerCityValue))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        btnCancel.setText("Annuller");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        btnConfirm.setText("Bekræft");
        btnConfirm.setEnabled(false);
        btnConfirm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConfirmActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlButtonsLayout = new javax.swing.GroupLayout(pnlButtons);
        pnlButtons.setLayout(pnlButtonsLayout);
        pnlButtonsLayout.setHorizontalGroup(
            pnlButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlButtonsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnConfirm)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancel)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlButtonsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCancel, btnConfirm});

        pnlButtonsLayout.setVerticalGroup(
            pnlButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlButtonsLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnConfirm)
                    .addComponent(btnCancel))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pnlSale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(pnlCustomer, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlDelivery, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlButtons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pnlCustomer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(pnlDelivery, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlButtons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(78, Short.MAX_VALUE))
            .addComponent(pnlSale, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        String itemNo = txtItemNo.getText();
        int qty = Integer.parseInt(txtQty.getText());
        if (itemNo.length() <= 0) {
            JOptionPane.showMessageDialog(this, "Indtast et varenummer", null, JOptionPane.WARNING_MESSAGE);
            return;
        }

        if (qty == 0) {
            JOptionPane.showMessageDialog(this, "Du kan ikke indtaste 0 (nul) som antal", null, JOptionPane.WARNING_MESSAGE);
            return;
        }

        try {
            controller.addItem(itemNo, qty);
            // update table
            tableModel.fireTableRowsInserted(0, 10);

            // update total
            updateTotal();
            txtItemNo.setText(null);
            txtQty.setText("1");
            txtItemNo.requestFocus();

        } catch (NoSuchItemException ex) {
            JOptionPane.showMessageDialog(this, "Varen findes ikke", null, JOptionPane.WARNING_MESSAGE);
            return;
        } catch (NoOpenSaleException ex) {
            JOptionPane.showMessageDialog(this, "Der er ikke noget åbent salg", null, JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        if(tableModel.getRowCount() > 0) {
            btnConfirm.setEnabled(true);
        }
    }//GEN-LAST:event_btnAddActionPerformed

    private void updateTotal() {

        String format = "%.2f";
        Double total = controller.getSale().getTotal();
        lblTotalDisplay.setText(String.format(format, total));

        Double subTotal = controller.getSale().getSubTotal();
        lblSubTotalDispl.setText(String.format(format, subTotal));

        Double savings = controller.getSaleSavings();
        lblDiscountDisplay.setText(String.format(format, savings));

        Double deliveryPrice;

        try {
            deliveryPrice = controller.getSale().getDelivery().getPrice();
        } catch (NullPointerException npe) {
            deliveryPrice = 0.0;
        }

        lblDeliveryDisplay.setText(String.format(format, deliveryPrice));
    }

    private void deleteSelectedRows() {
        int[] selection = tblItems.getSelectedRows();

        if (selection.length == 0) {
            return;
        }

        OrderLineItem line;
        OrderLineItem[] lines = controller.getSaleLineItems();

        for (int index : selection) {
            line = lines[index];
            controller.removeSaleLine(line);
        }

        Arrays.sort(selection);

        int min = selection[0];
        int max = selection[selection.length - 1];

        tableModel.fireTableRowsDeleted(min, max);
        updateTotal();
        
        if(tableModel.getRowCount() == 0) {
            btnConfirm.setEnabled(false);
        }
    }

    private void updateCustomerInfo() {
        Customer customer = controller.getSale().getCustomer();

        String customerName;
        String customerAddress;
        String customerZipCode;
        String customerCity;

        if (customer == null) {
            customerName = "";
            customerAddress = "";
            customerZipCode = "    ";
            customerCity = "";
        } else {
            customerName = customer.getName();
            customerAddress = customer.getAddress();
            customerZipCode = Integer.toString(customer.getZipCode());
            customerCity = customer.getCity();
        }

        lblCustomerNameValue.setText(customerName);
        lblCustomerAddressValue.setText(customerAddress);
        lblCustomerZipCodeValue.setText(customerZipCode);
        lblCustomerCityValue.setText(customerCity);
    }

    private void txtDeliveryNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDeliveryNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDeliveryNameActionPerformed

    private void txtDeliveryZipCodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDeliveryZipCodeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDeliveryZipCodeActionPerformed

    private void txtDeliveryCityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDeliveryCityActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDeliveryCityActionPerformed

    private void txtDeliveryPriceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDeliveryPriceActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDeliveryPriceActionPerformed

    private void btnReadCustomerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReadCustomerActionPerformed
        try {
            int phone = Integer.parseInt(txtPhone.getText());
            
            throw new UnsupportedOperationException("Not yet implemented");
/*
            if (controller.useCustomerAccount(phone)) {
                // update customer information

                Customer customer = controller.getSale().getCustomer();

                updateCustomerInfo();
                btnDeliveryUseCustomerInfo.setEnabled(true);
            } else {
                JOptionPane.showMessageDialog(pnlCustomer, "Ingen kunde fundet", null, JOptionPane.WARNING_MESSAGE);
            }
*/
        } catch (NumberFormatException nfe) {
            JOptionPane.showMessageDialog(pnlCustomer, "Ikke et gyldigt nummer", null, JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_btnReadCustomerActionPerformed

    private void txtPhoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPhoneActionPerformed
        btnReadCustomerActionPerformed(evt);
    }//GEN-LAST:event_txtPhoneActionPerformed

    private void btnDeliveryUseCustomerInfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeliveryUseCustomerInfoActionPerformed

        Customer customer = controller.getSale().getCustomer();
        if (customer == null) {
            JOptionPane.showMessageDialog(pnlCustomer, "Ingen kunde er tilknyttet salget",
                    null, JOptionPane.WARNING_MESSAGE);
        } else {

            txtDeliveryName.setText(customer.getName());
            txtDeliveryAddress.setText(customer.getAddress());
            txtDeliveryZipCode.setText(Integer.toString(customer.getZipCode()));
            txtDeliveryCity.setText(customer.getCity());

            txtDeliveryPrice.requestFocus();
        }

    }//GEN-LAST:event_btnDeliveryUseCustomerInfoActionPerformed

    private void txtDeliveryNameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDeliveryNameFocusLost
    }//GEN-LAST:event_txtDeliveryNameFocusLost

    private void btnDeliverySaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeliverySaveActionPerformed

        String name = txtDeliveryName.getText();
        String address = txtDeliveryAddress.getText();
        String city = txtDeliveryCity.getText();
        int zipCode;
        double price;

        try {
            zipCode = Integer.parseInt(txtDeliveryZipCode.getText());
        } catch (NumberFormatException nfe) {
            JOptionPane.showMessageDialog(this, "Postnummer indeholder ikke "
                    + "en gyldig værdi", null, JOptionPane.WARNING_MESSAGE);
            return;
        }

        try {
            price = NumberFormat.getInstance().parse(txtDeliveryPrice.getText()).doubleValue();
        } catch (ParseException pe) {
            JOptionPane.showMessageDialog(this, "Prisfeltet for leveringen "
                    + "indeholder ikke en gyldig værdi.", null,
                    JOptionPane.WARNING_MESSAGE);
            return;
        }

        // create delivery
        controller.createDelivery(name, address, zipCode, city, price);
        updateDeliveryFields();
        updateTotal();
    }//GEN-LAST:event_btnDeliverySaveActionPerformed

    private void txtItemNoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtItemNoActionPerformed
        btnAddActionPerformed(evt);
    }//GEN-LAST:event_txtItemNoActionPerformed

    private void btnRemoveLinesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveLinesActionPerformed
        deleteSelectedRows();
    }//GEN-LAST:event_btnRemoveLinesActionPerformed

    private void txtDiscountPctFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDiscountPctFocusLost
        try {
            controller.setDiscount(Double.parseDouble(txtDiscountPct.getText()));
            updateTotal();
        } catch (NumberFormatException nfe) {
            JOptionPane.showMessageDialog(this, "Indtast et gydigt tal", null, JOptionPane.WARNING_MESSAGE);
            txtDiscountPct.setText("0");
        }
    }//GEN-LAST:event_txtDiscountPctFocusLost

    private void tblItemsKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tblItemsKeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
            deleteSelectedRows();
            tblItems.clearSelection();
        }
    }//GEN-LAST:event_tblItemsKeyReleased

    private void txtQtyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtQtyActionPerformed
        btnAddActionPerformed(evt);
    }//GEN-LAST:event_txtQtyActionPerformed

    private void txtQtyFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtQtyFocusGained
        txtQty.selectAll();
    }//GEN-LAST:event_txtQtyFocusGained

    private void btnCustomerClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCustomerClearActionPerformed
        controller.getSale().clearCustomer();
        updateCustomerInfo();
        btnDeliveryUseCustomerInfo.setEnabled(false);
    }//GEN-LAST:event_btnCustomerClearActionPerformed

    private void btnDeliveryClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeliveryClearActionPerformed
        controller.clearSaleDelivery();
        updateDeliveryFields();
        updateTotal();
    }//GEN-LAST:event_btnDeliveryClearActionPerformed

    private void btnConfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConfirmActionPerformed

    }//GEN-LAST:event_btnConfirmActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed

        dispose();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void txtDiscountPctFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDiscountPctFocusGained
        txtDiscountPct.selectAll();
    }//GEN-LAST:event_txtDiscountPctFocusGained

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnConfirm;
    private javax.swing.JButton btnCustomerClear;
    private javax.swing.JButton btnDeliveryClear;
    private javax.swing.JButton btnDeliverySave;
    private javax.swing.JButton btnDeliveryUseCustomerInfo;
    private javax.swing.JButton btnReadCustomer;
    private javax.swing.JButton btnRemoveLines;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblCustomerAddress;
    private javax.swing.JLabel lblCustomerAddressValue;
    private javax.swing.JLabel lblCustomerCity;
    private javax.swing.JLabel lblCustomerCityValue;
    private javax.swing.JLabel lblCustomerName;
    private javax.swing.JLabel lblCustomerNameValue;
    private javax.swing.JLabel lblCustomerZipCode;
    private javax.swing.JLabel lblCustomerZipCodeValue;
    private javax.swing.JLabel lblDelivery;
    private javax.swing.JLabel lblDeliveryAddress;
    private javax.swing.JLabel lblDeliveryCity;
    private javax.swing.JLabel lblDeliveryDisplay;
    private javax.swing.JLabel lblDeliveryName;
    private javax.swing.JLabel lblDeliveryPrice;
    private javax.swing.JLabel lblDeliveryZipCode;
    private javax.swing.JLabel lblDiscount;
    private javax.swing.JLabel lblDiscountDisplay;
    private javax.swing.JLabel lblDiscountInput;
    private javax.swing.JLabel lblDiscountPct;
    private javax.swing.JLabel lblItemNo;
    private javax.swing.JLabel lblPhone;
    private javax.swing.JLabel lblQty;
    private javax.swing.JLabel lblSubTotal;
    private javax.swing.JLabel lblSubTotalDispl;
    private javax.swing.JLabel lblTotal;
    private javax.swing.JLabel lblTotalDisplay;
    private javax.swing.JPanel pnlButtons;
    private javax.swing.JPanel pnlCustomer;
    private javax.swing.JPanel pnlDelivery;
    private javax.swing.JPanel pnlSale;
    private javax.swing.JPanel pnlTotals;
    private javax.swing.JTable tblItems;
    private javax.swing.JTextField txtDeliveryAddress;
    private javax.swing.JTextField txtDeliveryCity;
    private javax.swing.JTextField txtDeliveryName;
    private javax.swing.JTextField txtDeliveryPrice;
    private javax.swing.JTextField txtDeliveryZipCode;
    private javax.swing.JTextField txtDiscountPct;
    private javax.swing.JTextField txtItemNo;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtQty;
    // End of variables declaration//GEN-END:variables

    private void updateDeliveryFields() {
        Delivery delivery = controller.getSale().getDelivery();

        String name;
        String address;
        int zipCode;
        String city;
        double price;

        if (delivery == null) {
            delivery = new Delivery(null);
        }

        name = delivery.getName();
        address = delivery.getAddress();
        zipCode = delivery.getZipCode();
        city = delivery.getCity();
        price = delivery.getPrice();

        txtDeliveryName.setText(name);
        txtDeliveryAddress.setText(address);
        txtDeliveryZipCode.setText(Integer.toString(zipCode));
        txtDeliveryCity.setText(city);
        txtDeliveryPrice.setText(String.format("%.2f", price));

    }
}
